<script setup>
import { introApi } from "@/services/index";
import { onLoad, onShow } from "@dcloudio/uni-app";
import { nextTick, ref, watch, onMounted } from "vue";
import { appInfo, loginSwitch } from "@/services/user";
import topNav from "../../components/topNav.vue";
import { operation } from "@/utils/num.js";
import { appOrderCreate, getProductByBarCode } from "@/services/cashier";

const goodsList = ref([]);
const payNum = ref(0);
const payPrice = ref(0);
const oldPayPrice = ref(0);
const goodsListNo = ref([]);
const sand_code = ref("");

onShow(() => {
  if (uni.getStorageSync("barCode")) {
    sand_code.value = uni.getStorageSync("barCode");
    getProductByBarCodeFun();
  }
  // 2175787542796
  // sand_code.value = "2200006001508";
  // getProductByBarCodeFun();

  //   console.log(goodsList.value);
  //   console.log(goodsListNo.value);
});

onLoad((e) => {
  if (uni.getStorageSync("goods")) {
    goodsList.value = JSON.parse(uni.getStorageSync("goods"));
    goodsList.value.forEach((item) => {
      if (item.weight && item.weight > 0) {
        item.price = item.price ? item.price : item.totalPrice;
        payNum.value = payNum.value + item.orderNum;
        item.totalPrice = operation(item.orderNum, item.weight, 2, "multiply");
        payPrice.value = operation(
          payPrice.value,
          operation(item.totalPrice, item.orderNum, 2, "multiply"),
          2,
          "add"
        );
      } else {
        item.price = item.price ? item.price : item.totalPrice;
        payNum.value = payNum.value + item.orderNum;
        payPrice.value = operation(
          payPrice.value,
          operation(
            item.orderNum,
            item.price ? item.price : item.totalPrice,
            2,
            "multiply"
          ),
          2,
          "add"
        );
        item.totalPriceShop = operation(
          item.orderNum,
          item.price ? item.price : item.totalPrice,
          2,
          "multiply"
        );
      }
    });
  }
  if (uni.getStorageSync("goodsNo")) {
    goodsListNo.value = JSON.parse(uni.getStorageSync("goodsNo"));
    goodsListNo.value.forEach((item) => {
      payNum.value = payNum.value + item.orderNum;
      payPrice.value = operation(
        payPrice.value,
        operation(item.orderNum, item.salePrice, 2, "multiply"),
        2,
        "add"
      );
    });
  }
  if (goodsList.value.length <= 0 && goodsListNo.value.length <= 0) {
    uni.redirectTo({ url: "/pages/index/index" });
  }
  console.log(goodsList.value);
});

const saveFun = () => {
  console.log("保存");
  //   console.log(form.value);
  // console.log(fileList.value[0].content);
  //   formMode.value.submit();
};
const value = ref(0);
const show = ref(false);

// 定义方法
const valChange = (e, item2) => {
  console.log(e);

  let num = 0;
  let price = 0;

  setTimeout(() => {
    if (item2.weight && item2.weight > 0) {
      item2.totalPriceShop = operation(
        item2.orderNum,
        item2.totalPrice,
        2,
        "multiply"
      );
    } else {
      item2.totalPriceShop = operation(
        item2.orderNum,
        item2.price ? item2.price : item2.totalPrice,
        2,
        "multiply"
      );
    }
    goodsList.value.forEach((item) => {
      if (item.weight && item.weight > 0) {
        num = num + item.orderNum;
        if (
          operation(item.orderNum, item.totalPrice, 2, "multiply") ==
          item.totalPriceShop
        ) {
          price = operation(
            price,
            operation(item.orderNum, item.totalPrice, 2, "multiply"),
            2,
            "add"
          );
        } else {
          price = operation(price, item.totalPriceShop, 2, "add");
        }
      } else {
        num = num + item.orderNum;
        if (
          operation(
            item.orderNum,
            item.price ? item.price : item.totalPrice,
            2,
            "multiply"
          ) == item.totalPriceShop
        ) {
          price = operation(
            price,
            operation(
              item.orderNum,
              item.price ? item.price : item.totalPrice,
              2,
              "multiply"
            ),
            2,
            "add"
          );
        } else {
          price = operation(price, item.totalPriceShop, 2, "add");
        }
      }
    });
    goodsListNo.value.forEach((item) => {
      console.log(item);
      num = num + item.orderNum;
      if (
        operation(item.orderNum, item.salePrice, 2, "multiply") ==
        item.totalPrice
      ) {
        price = operation(
          price,
          operation(item.orderNum, item.salePrice, 2, "multiply"),
          2,
          "add"
        );
      } else {
        price = operation(price, totalPriceShop, 2, "add");
      }
    });

    payPrice.value = price;
    payNum.value = num;
    uni.setStorageSync("goods", JSON.stringify(goodsList.value));
    uni.setStorageSync("goodsNo", JSON.stringify(goodsListNo.value));

    // if (payNum.value == 0) {
    //   popupshow.value = false;
    // }
  }, 100);
};
const confirmModal = () => {
  goodsList.value.forEach((item) => {
    item.orderNum = 0;
  });
  payNum.value = 0;
  show.value = false;

  uni.redirectTo({ url: "/pages/cashier/goods/index" });
};
const rightClick = () => {
  console.log("rightClick");
};

const leftClick = () => {
  console.log("leftClick");
};
// const goPay = () => {
//   uni.navigateTo({
//     url: "/pages/cashier/goods_confirm/index",
//   });
// };
//清空
const clearFun = () => {
  show.value = true;
};

//支付
const isPay = ref(false);

const goPay = async () => {
  if (isPay.value == true) {
    return;
  }

  isPay.value = true;
  uni.showLoading({
    title: "提交中",
    mask: true,
  });

  let data = [];
  let upPrice = 0;
  let newUpPrice = 0;
  console.log(goodsList.value);
  goodsList.value.forEach((element) => {
    if (element.weight && element.weight > 0) {
      if (element.orderNum > 0) {
        data.push({
          productId: element.id,
          orderNum: element.orderNum,
          weight: element.weight,
          totalPrice: element.totalPrice,
        });
        if (element.oldprice > 0) {
          if (
            operation(element.orderNum, Number(element.price), 2, "multiply") ==
            element.totalPriceShop
          ) {
            upPrice = operation(
              upPrice,
              operation(
                element.orderNum,
                operation(
                  Number(element.oldprice),
                  Number(element.price),
                  2,
                  "subtract"
                ),
                2,
                "multiply"
              ),
              2,
              "add"
            );
          } else {
            upPrice = operation(
              upPrice,

              operation(
                operation(
                  element.orderNum,
                  Number(element.oldprice),
                  2,
                  "multiply"
                ),
                Number(element.totalPriceShop),
                2,
                "subtract"
              ),

              2,
              "add"
            );
          }
        }
      }
    } else {
      if (element.orderNum > 0) {
        data.push({
          productId: element.id,
          orderNum: element.orderNum,
          price: element.price,
        });
        if (element.oldprice > 0) {
          if (
            operation(element.orderNum, Number(element.price), 2, "multiply") ==
            element.totalPriceShop
          ) {
            console.log("相等");
            upPrice = operation(
              upPrice,
              operation(
                element.orderNum,
                operation(
                  Number(element.oldprice),
                  Number(element.price),
                  2,
                  "subtract"
                ),
                2,
                "multiply"
              ),
              2,
              "add"
            );
          } else {
            upPrice = operation(
              upPrice,

              operation(
                operation(
                  element.orderNum,
                  Number(element.oldprice),
                  2,
                  "multiply"
                ),
                Number(element.totalPriceShop),
                2,
                "subtract"
              ),

              2,
              "add"
            );
            newUpPrice = operation(
              newUpPrice,
              operation(
                operation(
                  element.orderNum,
                  Number(element.price),
                  2,
                  "multiply"
                ),
                Number(element.totalPriceShop),
                2,
                "subtract"
              ),
              2,
              "add"
            );
          }
        }
      }
    }
  });
  console.log("upPrice", upPrice, newUpPrice);

  goodsListNo.value.forEach((element) => {
    if (element.orderNum > 0 && element.salePrice > 0) {
      data.push({
        productId: element.id,
        orderNum: element.orderNum,
        price: element.salePrice,
      });
    }
  });
  if (data.length <= 0) {
    isPay.value = false;
    return uni.showToast({
      title: "请选择商品",
      icon: "none",
    });
  }

  uni.setStorageSync("goods", JSON.stringify(goodsList.value));
  uni.setStorageSync("goodsNo", JSON.stringify(goodsListNo.value));

  try {
    let res = await appOrderCreate({ products: data });
    if (res.code == 200) {
      isPay.value = false;
      uni.hideLoading();

      uni.navigateTo({
        url:
          "/pages/cashier/goods_confirm/index?id=" +
          res.data.id +
          "&price=" +
          payPrice.value +
          "&payNum=" +
          payNum.value +
          "&upPrice=" +
          upPrice +
          "&newUpPrice=" +
          newUpPrice,
      });

      // let resData = res.data.datas;
    } else {
      uni.showToast({
        title: res.msg,
        icon: "none",
        mask: true,
      });
      isPay.value = false;
      uni.hideLoading();
    }

    console.log(res);
  } catch (e) {
    uni.showToast({
      title: e.msg,
      icon: "none",
      mask: true,
    });
    uni.hideLoading();
    isPay.value = false;
  }
};

const keyWord = ref(null);
const priceValue = ref(0);
const selectType = ref(1);
const selectTypeIndex = ref(0);
const selectItemObj = ref({});

const selectNumIndex = ref(-1);
const del = (e) => {
  if (e == 0) {
    selectNumIndex.value = selectNumIndex.value - 1;
  } else if (e == 1) {
    selectNumIndex.value = selectNumIndex.value + 1;
  }
};
const selectPriceType = ref(1);
const keyWordItem = (index, type) => {
  console.log(index, type);
  if (type == 1) {
    // priceValue.value= selectItemObj.value
    if (selectType.value == 1) {
      if (selectItemObj.value.weight && selectItemObj.value.weight > 0) {
        priceValue.value = String(item.totalPrice);
        if (selectItemObj.value.oldprice && selectItemObj.value.oldprice > 0) {
        } else {
          selectItemObj.value.oldprice = selectItemObj.value.totalPrice;
        }
      } else {
        priceValue.value = String(selectItemObj.value.price);

        if (selectItemObj.value.oldprice && selectItemObj.value.oldprice > 0) {
        } else {
          selectItemObj.value.oldprice = selectItemObj.value.price;
        }
      }
    }
    if (selectType.value == 2) {
      priceValue.value = String(selectItemObj.value.salePrice);
    }
  } else {
    priceValue.value = String(selectItemObj.value.totalPriceShop);
  }

  selectPriceType.value = type;
  selectNumIndex.value = index;
};
const inp = (e) => {
  if (selectPriceType.value == 1) {
    selectItemObj.value.price = Number(e);
    selectItemObj.value.totalPriceShop = operation(
      Number(e),
      Number(selectItemObj.value.orderNum),
      2,
      "multiply"
    );
  } else {
    selectItemObj.value.totalPriceShop = Number(e);
  }
};

//金额键盘

const hide = () => {
  // if (num.value > 0) {
  // } else {
  //   jsnum.value = 0;
  // }
  // isPayShow.value = false;
  keyWord.value.close();
};
const confirm = async () => {
  if (priceValue.value <= 0) {
    uni.showToast({
      title: "请输入正确金额",
      icon: "none",
    });
    return;
  }

  // if (
  //   selectItemObj.value.price &&
  //   selectItemObj.value.totalPriceShop >
  //     operation(
  //       selectItemObj.value.orderNum,
  //       Number(selectItemObj.value.price),
  //       2,
  //       "multiply"
  //     )
  // ) {
  //   uni.showToast({
  //     title: "调整金额不能大于(单价*数量)",
  //     icon: "none",
  //   });
  //   return;
  // }

  if (selectType.value == 1) {
    if (goodsList.value[selectTypeIndex.value].oldprice > 0) {
      // if (
      //   goodsList.value[selectTypeIndex.value].oldprice <
      //   Number(priceValue.value)
      // ) {
      //   uni.showToast({
      //     title: "商品调价不能大于售价",
      //     icon: "none",
      //   });
      //   selectNumIndex.value = -1;
      //   keyWord.value.open();
      //   return;
      // }
    } else {
      if (
        goodsList.value[selectTypeIndex.value].weight &&
        goodsList.value[selectTypeIndex.value].weight > 0
      ) {
        if (
          goodsList.value[selectTypeIndex.value].totalPrice <
          Number(priceValue.value)
        ) {
          uni.showToast({
            title: "商品调价不能大于售价",
            icon: "none",
          });
          selectNumIndex.value = -1;
          keyWord.value.open();
          return;
        }
      } else {
        if (
          goodsList.value[selectTypeIndex.value].price <
          Number(priceValue.value)
        ) {
          uni.showToast({
            title: "商品调价不能大于售价",
            icon: "none",
          });
          selectNumIndex.value = -1;
          keyWord.value.open();
          return;
        }
      }
    }

    if (
      goodsList.value[selectTypeIndex.value].weight &&
      goodsList.value[selectTypeIndex.value].weight > 0
    ) {
      goodsList.value[selectTypeIndex.value].totalPrice = Number(
        priceValue.value
      );
    } else {
      goodsList.value[selectTypeIndex.value].price = Number(
        selectItemObj.value.price
      );
      goodsList.value[selectTypeIndex.value].totalPriceShop = Number(
        selectItemObj.value.totalPriceShop
      );
    }
  }
  if (selectType.value == 2) {
    goodsListNo.value[selectTypeIndex.value].salePrice = Number(
      priceValue.value
    );
  }
  let num = 0;
  let price = 0;

  goodsList.value.forEach((item) => {
    if (item.weight && item.weight > 0) {
      num = num + item.orderNum;
      if (
        operation(item.orderNum, item.totalPrice, 2, "multiply") ==
        item.totalPriceShop
      ) {
        price = operation(
          price,
          operation(item.orderNum, item.totalPrice, 2, "multiply"),
          2,
          "add"
        );
      } else {
        price = operation(price, item.totalPriceShop, 2, "add");
      }
    } else {
      num = num + item.orderNum;

      if (
        operation(
          item.orderNum,
          item.price ? item.price : item.totalPrice,
          2,
          "multiply"
        ) == item.totalPriceShop
      ) {
        price = operation(
          price,
          operation(
            item.orderNum,
            item.price ? item.price : item.totalPrice,
            2,
            "multiply"
          ),
          2,
          "add"
        );
      } else {
        price = operation(price, item.totalPriceShop, 2, "add");
      }
      // price = operation(
      //   price,
      //   operation(item.orderNum, item.price, 2, "multiply"),
      //   2,
      //   "add"
      // );
    }
  });
  goodsListNo.value.forEach((item) => {
    num = num + item.orderNum;
    if (
      operation(item.orderNum, item.salePrice, 2, "multiply") == item.totalPrice
    ) {
      price = operation(
        price,
        operation(item.orderNum, item.salePrice, 2, "multiply"),
        2,
        "add"
      );
    } else {
      price = operation(price, totalPriceShop, 2, "add");
    }
  });

  payPrice.value = price;
  payNum.value = num;

  // getcomputeBrokerage(Number(num.value));
  // productDataNo.value[selectNo.value].salePrice = Number(priceValue.value);
  // productDataNo.value[selectNo.value].orderNum = 1;

  // payPrice.value = operation(
  //   payPrice.value,
  //   Number(priceValue.value),
  //   2,
  //   "add"
  // );
};
const closePay = () => {
  // isPayShow.value = false;
  keyWord.value.close();
};
const priceClick = (item, index, type) => {
  if (!item.storePricing) {
    return;
  }
  selectPriceType.value = 1;
  if (item.weight && item.weight > 0) return;
  selectItemObj.value = JSON.parse(JSON.stringify(item));
  selectTypeIndex.value = index;
  selectType.value = type;

  console.log("item", selectTypeIndex.value, selectType.value);
  if (type == 1) {
    if (item.weight && item.weight > 0) {
      priceValue.value = String(item.totalPrice);
      if (item.oldprice && item.oldprice > 0) {
      } else {
        item.oldprice = item.totalPrice;
      }
    } else {
      priceValue.value = String(item.price);

      if (item.oldprice && item.oldprice > 0) {
      } else {
        item.oldprice = item.price;
      }
    }
    console.log("item", item, goodsList.value);
  }
  if (type == 2) {
    priceValue.value = String(item.salePrice);
  }
  selectNumIndex.value = -1;
  keyWord.value.open();
};

const ishowcamera = ref(false);
const addUitCode = () => {
  // #ifdef H5
  uni.navigateTo({
    url: "/pages/code_sand/index?type=addBarCode",
  });
  // #endif
  // #ifndef H5
  // 允许从相机和相册扫码
  // 允许从相机和相册扫码
  // #ifdef APP-PLUS

  const systemInfo = uni.getSystemInfoSync();
  if (systemInfo.osName === "android") {
    if (uni.getStorageSync("isspermission")) {
    } else {
      ishowcamera.value = true;
    }

    plus.android.requestPermissions(["android.permission.CAMERA"], (e) => {
      if (e.deniedAlways.length > 0) {
        // 弹出提示框解释为何需要权限，引导用户打开设置页面开启

        ishowcamera.value = false;
      } else if (e.deniedPresent.length > 0) {
        //权限被临时拒绝
        // 弹出提示框解释为何需要权限，可再次调用plus.android.requestPermissions申请权限
        ishowcamera.value = false;
      } else if (e.deniedAlways.length > 0) {
        //权限被永久拒绝
        // 弹出提示框解释为何需要权限，可再次调用plus.android.requestPermissions申请权限
        ishowcamera.value = false;
      } else {
        plus.android.requestPermissions(
          ["android.permission.READ_EXTERNAL_STORAGE"],
          (e) => {
            if (e.deniedAlways.length > 0) {
              // 弹出提示框解释为何需要权限，引导用户打开设置页面开启

              ishowcamera.value = false;
            } else if (e.deniedPresent.length > 0) {
              //权限被临时拒绝
              // 弹出提示框解释为何需要权限，可再次调用plus.android.requestPermissions申请权限

              ishowcamera.value = false;
            } else if (e.deniedAlways.length > 0) {
              //权限被永久拒绝
              // 弹出提示框解释为何需要权限，可再次调用plus.android.requestPermissions申请权限

              ishowcamera.value = false;
            } else {
              ishowcamera.value = false;
              uni.setStorageSync("isspermission", true);

              uni.scanCode({
                scanType: ["barCode", "qrCode"],
                autoDecodeCharset: true,
                autoZoom: true,
                success: function (res) {
                  console.log("条码类型：" + res.scanType);
                  console.log("条码内容：" + res.result);
                  sand_code.value = res.result;
                  getProductByBarCodeFun();
                },
              });
            }
          }
        );
      }
    });
    return;
  }

  // #endif
  uni.scanCode({
    scanType: ["barCode", "qrCode"],
    autoDecodeCharset: true,
    autoZoom: true,
    success: function (res) {
      console.log("条码类型：" + res.scanType);
      console.log("条码内容：" + res.result);
      sand_code.value = res.result;
      getProductByBarCodeFun();
    },
  });
  // #endif
};

const getProductByBarCodeFun = async () => {
  try {
    // let res = await getProductByBarCode({ barCode: "2200269012341" });
    let res = await getProductByBarCode({ barCode: sand_code.value });

    if (res.code == 200) {
      uni.removeStorageSync("barCode");

      payNum.value = payNum.value + res.data.orderNum;
      payPrice.value = operation(
        Number(payPrice.value),
        operation(
          Number(res.data.orderNum),
          res.data && res.data.weight && res.data.weight > 0
            ? Number(res.data.totalPrice)
            : res.data.price
            ? Number(res.data.price)
            : Number(res.data.totalPrice),
          2,
          "multiply"
        ),
        2,
        "add"
      );
      res.data.totalPriceShop = operation(
        Number(res.data.orderNum),
        res.data && res.data.weight && res.data.weight > 0
          ? Number(res.data.totalPrice)
          : res.data.price
          ? Number(res.data.price)
          : Number(res.data.totalPrice),
        2,
        "multiply"
      );
      goodsList.value.push(res.data);
      console.log("2", goodsList.value);
      if (uni.getStorageSync("barCode")) {
        uni.removeStorageSync("barCode");
      }
    } else {
      uni.showToast({
        title: res.message,
        icon: "none",
      });
      if (uni.getStorageSync("barCode")) {
        uni.removeStorageSync("barCode");
      }
    }
  } catch (e) {
    uni.showToast({
      title: e.message,
      icon: "none",
    });
    if (uni.getStorageSync("barCode")) {
      uni.removeStorageSync("barCode");
    }
  }
};
</script>

<template>
  <view class="bg">
    <jia-PayKeyboard
      :confirmStyle="{ backgroundColor: '#1679FB' }"
      class="keyWord-index"
      :overlayClose="true"
      ref="keyWord"
      v-model="priceValue"
      :sclectItem="selectNumIndex"
      @input="inp"
      @del="del"
      @confirm="confirm"
      @hide="hide"
      style="z-index: 1000"
    >
      <view class="PayKeyboard-k">
        <view class="icon-top">
          <up-icon
            @click="closePay"
            name="close"
            color="#86909C"
            size="30rpx"
          ></up-icon
        ></view>
        <view class="PayKeyboard-k-title">
          {{ selectItemObj.totalPriceShop
          }}<text>{{ selectItemObj.name }}</text>
        </view>
        <view class="link-to"></view>
        <view class="PayKeyboard-k-num">
          <view class="PayKeyboard-k-num-input">
            <view style="width: 50%" class="PayKeyboard-k-num-input-left">
              <view class="PayKeyboard-k-num-title">单价</view>
              <up-form labelPosition="left" ref="form1" labelWidth="0">
                <up-form-item
                  label=" "
                  borderBottom
                  ref="item1"
                  @click="keyWordItem(-1, 1)"
                >
                  <view class="PayKeyboard-k-num-input-text">
                    <view
                      class="num-view"
                      v-for="(item, index) in selectPriceType == 1
                        ? priceValue
                        : String(selectItemObj.price)"
                      :key="index"
                      @click.stop="keyWordItem(index, 1)"
                      ><view
                        class="input_lin"
                        v-if="selectNumIndex == index && selectPriceType == 1"
                      ></view
                      >{{ item }}</view
                    >
                    <view
                      class="input_lin"
                      v-if="selectNumIndex == -1 && selectPriceType == 1"
                    ></view>
                  </view>

                  <template #right>
                    <text>元</text>
                  </template>
                </up-form-item>
              </up-form>
            </view>
            <view style="width: 50%" class="PayKeyboard-k-num-input-right">
              <view class="PayKeyboard-k-num-title">总价</view>
              <up-form labelPosition="left" ref="form1" labelWidth="0">
                <up-form-item
                  label=" "
                  borderBottom
                  ref="item1"
                  @click="keyWordItem(-1, 2)"
                >
                  <view class="PayKeyboard-k-num-input-text">
                    <view
                      class="num-view"
                      v-for="(item, index) in selectPriceType == 2
                        ? priceValue
                        : String(selectItemObj.totalPriceShop)"
                      :key="index"
                      @click.stop="keyWordItem(index, 2)"
                      ><view
                        class="input_lin"
                        v-if="selectNumIndex == index && selectPriceType == 2"
                      ></view
                      >{{ item }}</view
                    >
                    <view
                      class="input_lin"
                      v-if="selectNumIndex == -1 && selectPriceType == 2"
                    ></view>
                  </view>

                  <template #right>
                    <text>元</text>
                  </template>
                </up-form-item>
              </up-form>
            </view>
          </view>
        </view>
      </view>
    </jia-PayKeyboard>

    <up-navbar
      title="手机收银"
      bgColor="#ffffff"
      @rightClick="rightClick"
      :autoBack="true"
      :safeAreaInsetTop="true"
      :fixed="true"
      :placeholder="true"
      :leftText="'返回'"
      :border="true"
    >
      <template #right>
        <view
          style="display: flex; justify-content: right; align-items: center"
        >
          <view class="popupcontent-title-right" @click="clearFun">
            <up-icon name="trash" color="#86909C" size="32rpx"></up-icon>
            <text>清空</text>
          </view>

          <view class="right-scan" @click="addUitCode">
            <van-icon
              style="font-weight: 500"
              name="scan"
              size="44rpx"
              color="#1D2129"
            />
          </view>
        </view>
        <!-- <text @click="clearFun">清空</text> -->
      </template>
    </up-navbar>
    <view class="content">
      <view v-for="(item, index) in goodsListNo" :key="index">
        <view class="content-item">
          <view class="content-item-left">
            <image
              src="https://cloud-erp.yibaitao.cn/0d2f4178-7754-4686-9213-b174f745258b.png"
              mode="scaleToFill"
          /></view>
          <view class="content-item-right">
            <view class="content-item-right-title">
              <text>{{ item.name }}</text>
            </view>
            <view class="content-item-right-num">
              <view class="content-item-right-num-left"><text></text> </view>
              <view class="content-item-right-num-right">
                <up-number-box
                  v-model="item.orderNum"
                  @change="(e) => valChange(e, item)"
                  min="0"
                  max="1"
                ></up-number-box>
              </view>
            </view>
            <view
              class="content-item-right-price"
              @click="priceClick(item, index, 2)"
              ><text>¥</text>{{ item.salePrice }}&nbsp; <text>总价¥</text
              >{{ item.totalPriceShop }} &nbsp;
              <up-icon name="edit-pen" color="#ff5722" size="42rpx"></up-icon
            ></view>
          </view>
        </view>
      </view>
      <view v-for="(item, index) in goodsList" :key="index">
        <view class="content-item">
          <view class="content-item-left">
            <text class="goods-item-cz"
              >{{ item.dhCode ? "称重" : "计件" }} </text
            ><image :src="item.image" mode="scaleToFill"
          /></view>
          <view class="content-item-right">
            <view class="content-item-right-title">
              <text>{{ item.name }}</text>
            </view>
            <view class="content-item-right-num">
              <view class="content-item-right-num-left"
                ><text>{{ item.categoryName }}</text>
              </view>
              <view class="content-item-right-num-right">
                <up-number-box
                  v-model="item.orderNum"
                  @change="(e) => valChange(e, item)"
                  min="0"
                  :max="item.weight && item.weight > 0 ? 1 : 9999"
                ></up-number-box>
              </view>
            </view>
            <view
              v-if="item.dhCode"
              class="content-item-right-price"
              @click="priceClick(item, index, 1)"
              ><text>总价¥</text>{{ item.totalPriceShop }} &nbsp;
              <up-icon
                v-if="!item.weight"
                name="edit-pen"
                color="#ff5722"
                size="42rpx"
              ></up-icon
            ></view>
            <view
              v-else
              class="content-item-right-price"
              @click="priceClick(item, index, 1)"
              ><text>¥</text
              >{{ item.price ? item.price : item.totalPrice }} &nbsp;<text
                >总价¥</text
              >{{ item.totalPriceShop }} &nbsp;
              <up-icon
                v-if="item.storePricing"
                name="edit-pen"
                color="#ff5722"
                size="42rpx"
              ></up-icon
            ></view>
          </view>
        </view>
      </view>
    </view>
    <view style="width: 100%; height: 150rpx"></view>
  </view>

  <view class="bt_form" v-permission="['shop:order:create']">
    <view class="bt_form_k">
      <view class="bt_form_k_left">
        <view class="price"
          ><text>¥</text>{{ payPrice }}
          <view class="price-num">已选{{ payNum }}件</view></view
        >
        <!-- <text class="bt_form_k_left_clear" @click="clearFun">清空</text> -->
      </view>
      <view class="bt_pay" @click="goPay">去结账</view>
    </view>
  </view>

  <up-modal
    :show="show"
    title="温馨提示"
    :showCancelButton="true"
    confirmText="确认"
    cancelText="取消"
    @cancel="show = false"
    @confirm="confirmModal"
  >
    <view class="slot-content">
      <rich-text :nodes="'确定清空选择结算商品？'"></rich-text>
    </view>
  </up-modal>

  <view class="show-camera" v-if="ishowcamera">
    <view class="show-camera-k">
      <view class="show-sm"> 设备权限使用说明 </view>
      <view class="show-des">
        为了给您带来更好的服务，需要获取您的相机权限与读取图片及文件权限，用于更换上传图片、扫一扫等功能，对于您授权的信息我们竭尽全力提供安全保护。
      </view>
    </view>
  </view>
</template>

<style lang="scss" scoped>
@import "index.scss";
</style>
